package com.site.common.aspect;

import com.site.common.annotation.Log;
import org.aspectj.lang.ProceedingJoinPoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;

import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Method;

/**
 * 记录日志
 */
public class LogAspect extends AbstractAspect {
    private static Logger logger = LoggerFactory.getLogger(LogAspect.class);

    @Override
    protected Object execute(ProceedingJoinPoint joinPoint, Method method, HttpServletRequest request) {
        Log log = method.getAnnotation(Log.class);
        logger.info("记录操作日志,{},{}", log.module(), log.action());
        this.saveLog();
        return null;
    }

    @Async
    public void saveLog(){
        logger.info("异步入库");
    }
}
